import { getAreaObj } from '@/utils/util'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{
			label: '消息通知标题',
			prop: 'noticeTitle',
		},
		{
			label: '消息通知内容',
			prop: 'noticeContent',
		},
		{
			label: '消息通知备注',
			prop: 'noticeNote',
		},
		{
			label: '消息通知类型',
			prop: 'noticeTypeLabel',
		},
		{
			label: '通知范围',
			prop: 'noticeScope',
			custome: 'tag',
			dataType: 'number',
			dicData: [
				{ label: '用户', value: 1 },
				{ label: '组织机构', value: 2 },
				{ label: '适应层级', value: 3 },
				{ label: '从业人员', value: 4 },
			],
			multiple: false,
			span: 12,
		},
		{
			label: '添加时间',
			prop: 'createTime',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const formConfig = {
	label: '数据管理设置',
	prop: 'base0',
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	column: [
		{
			label: '消息通知标题',
			prop: 'noticeTitle',
			type: 'input',
			span: 12,
		},
		{
			label: '消息通知类型',
			prop: 'noticeType',
			propName: 'noticeTypeLabel',
			type: 'remoteSelect',
			code: 'NOTICE_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
		},
		{
			label: '消息通知内容',
			prop: 'noticeContent',
			showWordLimit: true,
			type: 'ueditor',
			height: '20rem',
			span: 24,
		},
		{
			label: '消息通知备注',
			prop: 'noticeNote',
			type: 'textarea',
			span: 24,
		},
		{
			label: '通知范围',
			prop: 'noticeScope',
			type: 'select',
			dataType: 'number',
			dicData: [
				{ label: '用户', value: 1 },
				{ label: '组织机构', value: 2 },
				{ label: '适应层级', value: 3 },
				{ label: '从业人员', value: 4 },
			],
			multiple: false,
			control: (e, model) => {
				return {
					areaInfo: {
						display: e == 3,
					},
					receiveUserId: {
						display: [1, 2, 4].includes(e),
					},
					receiveOrganizationId: {
						display: e == 2,
					},
				}
			},
			span: 12,
		},
		{
			label: '适应层级',
			prop: 'areaInfo',
			propName: 'areaInfoName',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			span: 12,
			showLabel: false,
		},
		{
			label: '接收人',
			prop: 'receiveUserId',
			propLabel: 'receiveUserName',
			type: 'remoteSelect',
			api: 'sys_user_querypage',
			filterKey: 'userId',
			filterLabel: 'realName',
			multiple: false,
			span: 12,
		},
		{
			label: '接收机构',
			prop: 'receiveOrganizationId',
			propLabel: 'receiveOrganizationName',
			type: 'remoteSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'id',
			filterLabel: 'organizationName',
			multiple: false,
			span: 12,
		},
	],
}
const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '消息通知类型',
			prop: 'noticeType',
			propName: 'noticeTypeLabel',
			type: 'remoteSelect',
			code: 'NOTICE_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '消息通知标题',
			prop: 'noticeTitle',
			type: 'input',
			span: 8,
		},
		{
			label: '消息通知内容',
			prop: 'noticeContent',
			type: 'input',
			span: 8,
		},
	],
}

export const api = {
	index: 'view_sysNoticeRecordByBsc_page',
	add: 'view_sysNoticeRecord_add',
	edit: 'view_sysNoticeRecord_edit',
	delete: 'view_sysNoticeRecord_del',
}
export const baseConfig: any = {
	pageName: '消息通知管理',
	addLabel: '添加',
	dictcodes: [],
	rowKey: 'id',
	tipLabel: 'noticeTitle',
	api,
	auth: {
		...api,
		mulitSet: 'mulitSet',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: api.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: api.delete,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '65%',
	},
	searchConfig,
	tableConfig,
	formConfig,
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areas: any = getAreaObj(item, '', 'get')
			return {
				...item,
				areaInfo: areas.areaIds,
				areaInfoName: areas.names,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form.areaInfo)
			const areaNameObj: any = getAreaObj(form.areaInfoName)
			resolve({
				...form,
				...areaObj,
				...areaNameObj,
			})
		})
	},
}
